// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the LineItemService.
LineItemServiceInterface lineItemService =
user.getService(DfpService.V201208.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) {