// 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});