private static final String ACTIVITY_GROUP_ID = "INSERT_ACTIVITY_GROUP_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session,
int activityGroupId) throws Exception {
// Get the ActivityService.
ActivityServiceInterface activityService =
dfpServices.get(session, ActivityServiceInterface.class);
// Create a statement to only select active activities.
StatementBuilder statementBuilder = new StatementBuilder()
.where("activityGroupId = :activityGroupId and status = :status")
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("activityGroupId", activityGroupId)
.withBindVariableValue("status", ActivityStatus.ACTIVE.toString());
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get activities by statement.
ActivityPage page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Activity activity : page.getResults()) {