public static List<AdUnit> runExample(DfpServices dfpServices, DfpSession session)
throws Exception {
List<AdUnit> adUnits = Lists.newArrayList();
// Get the InventoryService.
InventoryServiceInterface inventoryService =
dfpServices.get(session, InventoryServiceInterface.class);
// Create a statement to select all ad units.
StatementBuilder statementBuilder = new StatementBuilder()
.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();
int i = page.getStartIndex();
for (AdUnit adUnit : page.getResults()) {