int offset = 0;
// Create a statement to only select line items from a given order.
String filterText = "WHERE orderId = :orderId LIMIT 500";
Statement filterStatement =
new StatementBuilder(filterText).putValue("orderId", orderId).toStatement();
// Collect all line item custom field IDs for an order.
Set<Long> customFieldIds = new HashSet<Long>();
do {
filterStatement.setQuery(filterText + " OFFSET " + offset);
// Get line items by statement.
page = lineItemService.getLineItemsByStatement(filterStatement);
// Get custom field IDs from the line items of an order.
if (page.getResults() != null) {
for (LineItem lineItem : page.getResults()) {
if (lineItem.getCustomFieldValues() != null) {
for (BaseCustomFieldValue customFieldValue : lineItem.getCustomFieldValues()) {
customFieldIds.add(customFieldValue.getCustomFieldId());
}
}
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
// Get the ReportService.
ReportServiceInterface reportService = user.getService(DfpService.V201311.REPORT_SERVICE);
// Create statement to filter for an order.
filterStatement =
new StatementBuilder("WHERE ORDER_ID = :orderId").putValue("orderId", orderId)
.toStatement();
// Create report job.
ReportJob reportJob = new ReportJob();