// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the PublisherQueryLanguageService.
PublisherQueryLanguageServiceInterface pqlService =
user.getService(DfpService.V201208.PUBLISHER_QUERY_LANGUAGE_SERVICE);
// Create statement to select all targetable cities.
// For criteria that do not have a "targetable" property, that predicate
// may be left off, i.e. just "SELECT * FROM Browser_Groups LIMIT 500"
String selectStatement = "SELECT * FROM City WHERE targetable = true LIMIT 500";
int offset = 0;
int resultSetSize = 0;
List<Row> allRows = new ArrayList<Row>();
ResultSet resultSet;
do {
StatementBuilder statementBuilder =
new StatementBuilder(selectStatement + " OFFSET " + offset);
// Get all cities.
resultSet = pqlService.select(statementBuilder.toStatement());
// Collect all cities from each page.
allRows.addAll(Arrays.asList(resultSet.getRows()));
// Display results.