// Get the LineItemService.
LineItemServiceInterface lineItemService =
dfpServices.get(session, LineItemServiceInterface.class);
// Create a statement to only select line items that need creatives.
StatementBuilder statementBuilder = new StatementBuilder()
.where("status = :status")
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("status", ComputedStatus.NEEDS_CREATIVES.toString());
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get line items by statement.
LineItemPage page =
lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (LineItem lineItem : page.getResults()) {
System.out.printf(
"%d) Line item with ID \"%d\" and name \"%s\" was found.\n", i++,
lineItem.getId(), lineItem.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d\n", totalResultSetSize);
}