// Get the AudienceSegmentService.
AudienceSegmentServiceInterface audienceSegmentService =
user.getService(DfpService.V201208.AUDIENCE_SEGMENT_SERVICE);
// Set defaults for page and filterStatement.
AudienceSegmentPage page;
Statement filterStatement = new Statement();
int offset = 0;
do {
// Create a statement to get all audience segments.
filterStatement.setQuery("LIMIT 500 OFFSET " + offset);
// Get audience segments by statement.
page = audienceSegmentService.getAudienceSegmentsByStatement(filterStatement);
if (page.getResults() != null) {
int i = page.getStartIndex();
for (AudienceSegment audienceSegment : page.getResults()) {
System.out.println(i + ") Audience segment with ID \"" + audienceSegment.getId()
+ "\" and name \"" + audienceSegment.getName() + "\" was found.");
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of results found: " + page.getTotalResultSetSize());
} catch (Exception e) {
e.printStackTrace();
}
}