try {
// Log SOAP XML request and response.
DfpServiceLogger.log();
// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the LineItemService.
LineItemServiceInterface lineItemService =
user.getService(DfpService.V201311.LINEITEM_SERVICE);
// Set the ID of the order to get line items from.
Long orderId = Long.parseLong("INSERT_ORDER_ID_HERE");
// Sets defaults for page and filterStatement.
LineItemPage page = new LineItemPage();
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();