String oneWeekAgo = new DateTime().minusDays(7).toString("yyyyMMdd");
String yesterday = new DateTime().minusDays(1).toString("yyyyMMdd");
selector.setDateRange(new DateRange(oneWeekAgo, yesterday));
selector.setPaging(new Paging(offset, PAGE_SIZE));
CampaignPage page = null;
do {
// Get all campaigns.
page = campaignService.get(selector);
// Display campaigns.
if (page.getEntries() != null) {
for (Campaign campaign : page.getEntries()) {
System.out.printf("Campaign with id \"%d\" and name \"%s\" had the following stats "
+ "during the last week.\n", campaign.getId(), campaign.getName());
System.out.printf(" Impressions: %d\n", campaign.getCampaignStats().getImpressions());
System.out.printf(" Clicks: %d\n", campaign.getCampaignStats().getClicks());
System.out.printf(" Cost: %.02f\n", campaign.getCampaignStats().getCost()
.getMicroAmount() / 1000000.0);
System.out.printf(" CTR: %.02f %%\n", campaign.getCampaignStats().getCtr() * 100.0);
}
} else {
System.out.println("No matching campaigns were found.");
}
offset += PAGE_SIZE;
selector.getPaging().setStartIndex(offset);
} while (offset < page.getTotalNumEntries());
}