Group objects based on a set of criteria.