// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the ContentService.
ContentServiceInterface contentService = user.getService(DfpService.V201308.CONTENT_SERVICE);
// Get the NetworkService.
NetworkServiceInterface networkService = user.getService(DfpService.V201308.NETWORK_SERVICE);
// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService =
user.getService(DfpService.V201308.CUSTOM_TARGETING_SERVICE);
// Get content browse custom targeting key ID.
long contentBrowseCustomTargetingKeyId =
networkService.getCurrentNetwork().getContentBrowseCustomTargetingKeyId();
// Create a statement to select the categories matching the name comedy.
Statement categoryFilterStatement = new StatementBuilder(
"WHERE customTargetingKeyId = :contentBrowseCustomTargetingKeyId " +
" and name = :category LIMIT 1")
.putValue("contentBrowseCustomTargetingKeyId", contentBrowseCustomTargetingKeyId)
.putValue("category", "comedy").toStatement();
// Get categories matching the filter statement.
CustomTargetingValuePage customTargetingValuePage =
customTargetingService.getCustomTargetingValuesByStatement(categoryFilterStatement);
// Get the custom targeting value ID for the comedy category.
long categoryCustomTargetingValueId = customTargetingValuePage.getResults()[0].getId();
// Set defaults for page and filterStatement.
ContentPage page = new ContentPage();
Statement filterStatement = new Statement();
int offset = 0;
do {
// Create a statement to get all active content.
filterStatement.setQuery("WHERE status = 'ACTIVE' LIMIT 500 OFFSET " + offset);
// Get content by statement.
page = contentService.getContentByStatementAndCustomTargetingValue(filterStatement,
categoryCustomTargetingValueId);
if (page.getResults() != null) {
int i = page.getStartIndex();
for (Content content : page.getResults()) {