code: private static List<AdUnit> getAllAdUnits(
        AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
      List<AdUnit> adUnits = new ArrayList<>();
  
      // Get the InventoryService.
      InventoryServiceInterface inventoryService =
          adManagerServices.get(session, InventoryServiceInterface.class);
  
      // Create a statement to select all ad units.
      StatementBuilder statementBuilder =
          new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
  
      // Default for total result set size.
      int totalResultSetSize = 0;
  
      do {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
  
        if (page.getResults() != null) {
          totalResultSetSize = page.getTotalResultSetSize();
          Collections.addAll(adUnits, page.getResults());
        }
  
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
      } while (statementBuilder.getOffset() < totalResultSetSize);
  
      return adUnits;
    }
docs: Get all ad units.