private static final String ADVERTISER_COMPANY_ID = "INSERT_ADVERTISER_COMPANY_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session,
long advertiserCompanyId) throws Exception {
// Get the ActivityGroupService.
ActivityGroupServiceInterface activityGroupService =
dfpServices.get(session, ActivityGroupServiceInterface.class);
// Create a short-term activity group.
ActivityGroup shortTermActivityGroup = new ActivityGroup();
shortTermActivityGroup.setName(
"Short-term activity group #" + new Random().nextInt(Integer.MAX_VALUE));
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().nextInt(Integer.MAX_VALUE));
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 createdActivityGroup : activityGroups) {
System.out.printf("An activity group with ID \"%d\" and name \"%s\" was created.\n",
createdActivityGroup.getId(), createdActivityGroup.getName());