// Get InventoryService.
InventoryServiceInterface inventoryService =
user.getService(DfpService.V201308.INVENTORY_SERVICE);
// Sets defaults for page and filterStatement.
AdUnitPage page = new AdUnitPage();
Statement filterStatement = new Statement();
int offset = 0;
do {
// Create a statement to get all ad units.
filterStatement.setQuery("LIMIT 500 OFFSET " + offset);
// Get ad units by statement.
page = inventoryService.getAdUnitsByStatement(filterStatement);
if (page.getResults() != null) {
adUnits.addAll(Arrays.asList(page.getResults()));
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
return adUnits.toArray(new AdUnit[] {});
}