// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the ReportService.
ReportServiceInterface reportService = user.getService(DfpService.V201306.REPORT_SERVICE);
// Create report job.
ReportJob reportJob = new ReportJob();
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDateRangeType(DateRangeType.LAST_WEEK);
reportQuery.setDimensions(new Dimension[] {Dimension.DATE, Dimension.AD_UNIT_NAME});
reportQuery.setColumns(new Column[] {Column.AD_SERVER_IMPRESSIONS,
Column.AD_SERVER_CLICKS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_IMPRESSIONS,
Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_CLICKS,
Column.TOTAL_INVENTORY_LEVEL_IMPRESSIONS,
Column.TOTAL_INVENTORY_LEVEL_CPM_AND_CPC_REVENUE});
reportQuery.setAdUnitView(ReportQueryAdUnitView.HIERARCHICAL);
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
do {
System.out.println("Report with ID '" + reportJob.getId() + "' is still running.");
Thread.sleep(30000);
// Get report job.
reportJob = reportService.getReportJob(reportJob.getId());
} while (reportJob.getReportJobStatus() == ReportJobStatus.IN_PROGRESS);
if (reportJob.getReportJobStatus() == ReportJobStatus.FAILED) {
System.out.println("Report job with ID '" + reportJob.getId()
+ "' failed to finish successfully.");