// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the ActivityGroupService.
ActivityGroupServiceInterface activityGroupService =
user.getService(DfpService.V201302.ACTIVITY_GROUP_SERVICE);
// Set the ID of the company for the activity group.
Long advertiserCompanyId = Long.parseLong("INSERT_ADVERTISER_COMPANY_ID_HERE");
// Create a short-term activity group.
ActivityGroup shortTermActivityGroup = new ActivityGroup();
shortTermActivityGroup.setName("Short-term activity group #" + new Random().nextLong());
shortTermActivityGroup.setCompanyIds(new long[] {advertiserCompanyId});
shortTermActivityGroup.setClicksLookback(1);
shortTermActivityGroup.setImpressionsLookback(1);
// Create a long-term activity group.
ActivityGroup longTermActivityGroup = new ActivityGroup();
longTermActivityGroup.setName("Long-term activity group #" + new Random().nextLong());
longTermActivityGroup.setCompanyIds(new long[] {advertiserCompanyId});
longTermActivityGroup.setClicksLookback(30);
longTermActivityGroup.setImpressionsLookback(30);
// Create the activity groups on the server.
ActivityGroup[] activityGroups = activityGroupService.createActivityGroups(
new ActivityGroup[] {shortTermActivityGroup, longTermActivityGroup});
for (ActivityGroup activityGroup : activityGroups) {
System.out.printf("An activity group with ID \"%d\" and name \"%s\" was created.\n",
activityGroup.getId(), activityGroup.getName());