---
title: Retrieve a set of agencies
summary: Load agencies with optional FEID and contract-type filters.
status: draft
owner: Technical Writer
last_reviewed: 2026-07-31
library: SAIF.Business.Policy.Agency
reference_type: package
operation_id: OP-002
trigger: A caller requests all agencies or filtered agencies.
---

# Retrieve a set of agencies

This operation retrieves an agency collection, optionally filtering by FEID or by the existence of matching contract types.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-002 |
| **Trigger** | A caller invokes one of the `clsAgencyCollection.GetAgencyCollection` overloads. |
| **Inputs** | `IDataPortalInfo`, optional FEID, optional `List(Of AgencyContractTypes)` |
| **Outputs** | `clsAgencyCollection` |
| **Primary components** | `clsAgencyCollection.GetAgencyCollection`, `clsAgencyCollection.Criteria`, `BeforeRetrieve`, `AfterRetrieve` |
| **Entry point** | `Business\SAIF.Business.Policy.Agency\clsAgencyCollection.vb` |

## Steps
1. Build the collection criteria that matches the requested overload: no filters, FEID filter, or contract-type filter list.
2. Compose [SQL-002](../sql/SQL-002-search-agencies-by-feid-and-contract-types.md) from the base agency query over [AGENCY](../database-tables.md#agency) and, when needed, a correlated `EXISTS` against [AGENCY_CONTRACT](../database-tables.md#agency_contract) ([BR-003](../business-rules.md#br-003-agency-feid-filters-agency-collections), [BR-004](../business-rules.md#br-004-contract-type-filters-use-correlated-contract-existence)).
3. Bind `:FederalEmployerID` only when the FEID path is used; contract-type codes are rendered as literals into the `IN` list.
4. If no criteria were supplied, execute the unfiltered agency query ([BR-005](../business-rules.md#br-005-empty-collection-criteria-returns-every-agency)).
5. Iterate the returned rows, create one `clsAgency` per row, and load each object into the collection.
6. Position the collection on its first item and return it to the caller ([BR-024](../business-rules.md#br-024-the-library-is-retrieve-only)).

## Process flow

The following diagram visualizes the collection retrieve path.

```mermaid
flowchart TD
  Start([GetAgencyCollection]) --> Criteria[Build criteria]
  Criteria --> Filter{Filter type}
  Filter --> None[No WHERE clause]
  Filter --> FEID[Add FEID predicate]
  Filter --> Contract[Add EXISTS contract predicate]
  None --> Exec[Execute SQL-002]
  FEID --> Exec
  Contract --> Exec
  Exec --> Load[Load clsAgency rows]
  Load --> End([Collection returned])
```

## Failure and edge-case behavior
- The parameterless overload reads every agency row.
- The contract-type filter uses literal interpolation for contract codes instead of parameter binding.

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Database tables](../database-tables.md)
- [SQL catalog](../sql/index.md)
- [API reference](../api/index.md)

## Sources
- `Business\SAIF.Business.Policy.Agency\clsAgencyCollection.vb`
- `Business\SAIF.Business.Policy.Agency\clsAgencyContract.vb`
